<template>
  <div class="printForm">
    <div class="area-header">
      <span class="area-header-title">{{ $t("申请单") }}</span>
    </div>
    <table class="printTable">
      <tr>
        <td class="tit">{{ $t('项目名称') }}</td>
        <td>{{ form.dealName }}</td>
        <td class="tit">{{ $t('标的公司名称') }}</td>
        <td>
          {{ form.companyName }}
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t("申请标题") }}</td>
        <td colspan="3">{{ form.actTitle }}</td>
      </tr>
      <tr>
        <td class="tit">{{ $t('项目负责人') }}</td>
        <td>{{ form.applicantName }}</td>
        <td class="tit">{{ $t('尽调方式') }}</td>
        <td>
          {{ ddModeFormat(form.ddMode) }}
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t('尽调类型') }}</td>
        <td colspan="3">
          {{ ddTypeFormat(form.ddType) }}
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t('尽调要求') }}</td>
        <td colspan="3">
          {{ form.ddAsk }}
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t('备注') }}</td>
        <td colspan="3">
          {{ form.remark }}
        </td>
      </tr>
    </table>
    <!-- 附件列表 -->
    <FileView
      :list.sync="form.fileList"
      data-type="deal_ddApply"
      :business-id="getDealId"
      :btn-show="!otherBtnHide"
    />
  </div>
</template>

<script>
import {
  getDealWfDdApply,
  getByWfNodeId
} from '@/api/deal/form/dealWfDdApply'
export default {
  data() {
    return {
      // 尽调类型
      ddTypeOptions: [],
      // 尽调方式
      ddModeOptions: [],
      // 项目id
      getDealId: this.$route.query.id,
      // 表单参数
      form: {
        ddType: [],
        fileList: []
      },
      // 操作按钮默认不展示
      buttonShow: true,
      // 是否隐藏保存按钮
      otherBtnHide: false
    }
  },
  mounted() {
    this.$bus.$emit('async_done')
  },
  created() {
    this.getDicts('dd_type').then((response) => {
      this.ddTypeOptions = response.data
    })
    this.getDicts('dd_mode').then((response) => {
      this.ddModeOptions = response.data
    })
  },
  methods: {
    // 初始化数据
    init(data) {
      if (data != null && data.id !== undefined) {
        getDealWfDdApply(data.id).then((response) => {
          this.form = response.data
        })
      } else {
        getByWfNodeId(data.wfNodeId).then((response) => {
          this.form = response.data
          this.form.fileList = data.fileList
          this.form.actTitle = data.actTitle
        })
      }
    },
    ddModeFormat(row) {
      return this.selectDictLabel(this.ddModeOptions, row)
    },
    ddTypeFormat(row) {
      if (row && row.length > 0) {
        var label = ''
        row.forEach(v => {
          var item = this.selectDictLabel(this.ddTypeOptions, v)
          label = label.concat(item + ',')
        })
        return label
      }
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        dealId: this.getDealId ? this.getDealId : undefined,
        companyId: undefined,
        userId: undefined,
        ddType: [],
        ddMode: undefined,
        ddAsk: undefined,
        actTitle: undefined,
        remark: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined
      }
      this.resetForm('form')
    }
  }
}
</script>
